<?php
require_once('../../libraryfiles/config.php');

$include = '
<link rel="stylesheet" href="'.W_ROOT.'/css/admin_style.css" />
<script type="text/javascript" src="'.W_ROOT.'/js/action.js"></script>
<script type="text/javascript" src="'.W_ROOT.'/js/common.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.9.1.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
';
$view = (isset($_GET['view'])) ? $_GET['view'] : '';
switch($view){
	case'add':
		if(isset($_GET['id'])){
			$id=(int)$_GET['id'];   
		}else if(isset($_POST['id'])){
			$id=$_POST['id'][0];
		}else $id = 0;
		$site_title = "Administrator Site - Add New Advertisement";
		$content = 'add.php';
		break;
		//this is case for delect for advertisement
	case 'delete':
		 if(isset($_GET['view']) && $_GET['view']=='delete'){
			 $id=$_GET['id'];
			 $image = '';
			 $img = mysql_query("SELECT * FROM ".Tbladvertise::tbladvertise." WHERE ".Tbladvertise::id."=".$id);
	       while($arr = mysql_fetch_array($img)){
		     $image = $arr['adv_upload_image'];
	       }
	        $sql = "DELETE FROM ".Tbladvertise::tbladvertise." WHERE ".Tbladvertise::id."=".$id;
	         mysql_query($sql);
	         @unlink('../../images/advertise/'.$image);
	         header('Location:'.base_url_admin.'/advertise/index.php?msg=delete_success');
			exit();
			 }
			 break;
		//this is case for edit banner
	case'edit':
		if(isset($_GET['id'])){
			$id=(int)$_GET['id'];   
		}else if(isset($_POST['id'])){
			$id=$_POST['id'][0];
		 }else $id = 0;
		 
		$site_title = "Administrator Site - Edit Advertisement";
		$content = 'formedit.php';
		break;
	//this is case for publish banner
	case 'publish' :
		if (isset($_GET['id']) && (int)$_GET['id'] > 0) {
			$id = (int)$_GET['id'];
		} else {
			header('Location:'.base_url_admin.'/advertise/index.php');
			exit();
		}
		if(isset($_GET['publish']) && (int)$_GET['publish']>=0 && (int)$_GET['publish']<=1){
			$publish = (int)$_GET['publish'];
		}else {
			header('Location:'.base_url_admin.'/advertise/index.php');
		 	exit();
		}
	//Statement to publish/unpublish User
	publishAdvertise('tbl_advertisement',$publish,$id);
	//header("Location:".base_url_admin."/advertise/index.php?".getAllGetParams(array('view','id','publish')));//page=".$page."&");
	header("Location:".base_url_admin."/advertise/index.php");
	exit();
	break;
	
	case 'unpublish' :
	publishAdvertise('tbl_advertisement',$publish,$id);
	//mysql_query("UPDATE tbl_advertisement SET adv_status=0 WHERE adv_id=".$_GET['id']);					  
    echo '<p style="color:#FF0000" align="center">advertisement have been blocked!<a href="#" onClick="history.go(-1)">Back</a></p>';
	
	default:
	$site_title = "Administrator Site - Advertisement";
	$content = 'list.php';
	break;
}

require_once TMP_ADMIN_PATH;
?>
